
<template>
<div>
  <el-table
      :data="tableData"
      stripe
      style="width: 100%">


    <el-table-column
        label="文件名"
        width="180">
      <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
          <p>文件名: {{ scope.row.dname }}</p>
          <p>文件大小: {{ scope.row.dsize }}(B)</p>
          <div slot="reference" class="name-wrapper">
            <el-button size="medium" style="border: none" @click="dirshow(scope.row.dname)">{{ scope.row.dname }}</el-button>
          </div>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column
        prop="ddate"
        label="上传日期"
        width="220">
    </el-table-column>
    <el-table-column
        prop="dsize"
        label="文件大小(B)"
        width="120">
    </el-table-column>
    <el-table-column
        prop="dtype"
        label="是否共享"
        width="300"
    >
      <template #default="scope">
        <el-switch v-model="scope.row.dtype==='is'" @change="shareC(scope.row.did,scope.row.dtype)" active-color="#13ce66" inactive-color="#ff4949">
        </el-switch>
      </template>
    </el-table-column>
    <el-table-column
        fixed="right"
        label="操作"
        width="300">
      <template #default="scope">
        <el-button @click="dirshow(scope.row.dname)" type="info" size="small"><li class="el-icon-search">查看</li></el-button>

        <el-button type="primary" size="small" @click="dirdown(scope.row.dname)" ><li class="el-icon-download">下载</li></el-button>
      </template>
    </el-table-column>
  </el-table>

</div>

</template>

<script>
export default {
  inject:　['reload','downloadFiles','dirdown'],

  created() {
    var th =this;
    axios({
      url:"/dir/findAllDir",
      method: "post",
    }).then((resp)=>{
    th.tableData=resp.data;

    })
  },
  methods: {

    shareC(did,dtype){
      var th=this
      var url="";
      if (dtype==='is'){
        url="http://82.156.197.128:8085/dir/offShare"
      }else {
        url="http://82.156.197.128:8085/dir/onShare"

      }
      axios({
        url:url,
        method:"POST",
        params:{
          "did":did
        }
      }).then((resp)=>{
        th.reload();
      })
    }
    ,
    dirshow(dname) {
      axios({
        url:"http://82.156.197.128:8085/user/downDir",
        method:"POST",
        params:{
          "dirname":dname
        },
        responseType:'blob'
      }).then((resp)=>{
        console.log("")
        console.log(resp)
        console.log(resp.data)
       window.open(window.URL.createObjectURL(resp.data),"_blank")
      })
    }
  },
  data() {
    return {
      iurl:'',
      tableData: [{
        did: '',
        dname: '',
        ddate: '',
        dtype: '',
        dsize: '',
      }]
    }
  }
}
</script>

<style>

</style>
